<?php

declare(strict_types=1);
/**
 * 服务启动时注册
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://doc.hyperf.io
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\SwooleEvent;

use App\Consul\ConsulServices;

class ServerStartCallback
{
    public function beforeStart()
    {
        //服务注册
        $registerService = [
            "ID"     => "php.micro.hbw.demo",
            "Name"   => "php.micro.hbw.demo",
            "Tags"   => ["primary"],
            "Address" => "127.0.0.1",
            "Port"   => 9501,
            "Check"  => [
                //"id"        => "api",多了这一行报错
                "name"      => "HTTPAPI on port 9501",
                "http"      => "http://hyperf-learn:9501/health",
                "interval"  => "5s",
                "timeout"   => "6s"
            ]
        ];
        $container = \Hyperf\Utils\ApplicationContext::getContainer();
        $consul = $container->get(ConsulServices::class);
        $consul->registerService($registerService);
        $consul->getService("php.micro.hbw.demo");
    }
}
